<template>
  <div class="loginbody">
    <div class="logindata">
      <div class="logintext">
        <h2>Welcome</h2>
      </div>
      <div class="formdata">
        <el-form ref="form">
          <el-form-item prop="username">
            <el-input
                v-model="user.username"
                clearable
                placeholder="请输入账号"
            ></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
                v-model="user.password"
                clearable
                placeholder="请输入密码"
                show-password
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="butt">
        <el-button type="primary" :loading="btnLoading" @click="login"
        >登录</el-button
        >
        <el-button class="shou">注册</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref} from 'vue'
import axios from "axios";
import {ElMessage} from "element-plus";
const btnLoading = ref(false)
const user = ref({
  username: '',
  password: ''
})


const login = () => {
  btnLoading.value = true
  // axios 属于异步请求
  axios.post('/api/user/login', user.value).then(res => {
    if(res.data.data === null){
      ElMessage({
        message: '用户名或密码不对',
        type: 'warning',
      })
    }else{
      ElMessage({
        message: '登录成功',
        type: 'success',
      })
    }
    btnLoading.value = false
  })

}

</script>

<style scoped>
.loginbody {
  width: 100%;
  height: 100%;
  min-width: 1000px;
  background-image: url("../assets/bg.jpg");
  background-size: 100% 100%;
  background-position: center center;
  overflow: auto;
  background-repeat: no-repeat;
  position: fixed;
  line-height: 100%;
  padding-top: 150px;
}

.logintext {
  margin-bottom: 20px;
  line-height: 50px;
  text-align: center;
  font-size: 30px;
  font-weight: bolder;
  color: white;
  text-shadow: 2px 2px 4px #000000;
}

.logindata {
  width: 400px;
  height: 300px;
  transform: translate(-50%);
  margin-left: 50%;
}

.tool {
  display: flex;
  justify-content: space-between;
  color: #606266;
}

.butt {
  margin-top: 10px;
  text-align: center;
}

.shou {
  cursor: pointer;
  color: #606266;
}

/*ui*/
/* /deep/ .el-form-item__label {
  font-weight: bolder;
  font-size: 15px;
  text-align: left;
}

/deep/ .el-button {
  width: 100%;
  margin-bottom: 10px;

} */
/**
随便
 */
</style>